<template>
    <el-form ref="form" label-width="80px">
        <el-form-item label="选择模型">
            <el-select v-model="index" placeholder="请选择类型">
                <el-option :label="item.title" :value="index" v-for="(item,index) in present" :key="index"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="选择字段" v-if="fields.length">
            <el-checkbox-group v-model="selected">
                <el-checkbox :label="index" name="type" v-for="(item,index) in fields" :key="index">{{item.title}}</el-checkbox>
            </el-checkbox-group>
        </el-form-item>
    </el-form>
</template>
<script type="text/javascript">
export default {
    props: {
        value: [Object, Array]
    },
    components: {
        //empty
    },
    data() {
        return {
            index: "",
            fields: [],
            selected: [],
            dialogVisible: false,
        };
    },
    /**
     * 计算属性
     * @type {Object}
     */
    computed: {
        present: function(argument) {
            return this.value.present
        },
        target: function(argument) {
            return this.value.target
        }
    },
    /**
     * 数据监听
     * @type {Object}
     */
    watch: {
        index(value) {
            this.fields = this.present[value].fields;
        }
    },
    /**
     * 页面加载执行
     * @return {[type]} [description]
     */
    async mounted() {

    },
    /**
     * 页面方法
     * @type {Object}
     */
    methods: {
        /**
         * 确认事件
         */
        handleAffirm() {
            console.log("执行到我的")
            let index = this.index;
            let present = {
                title: this.present[index].title,
                name: this.present[index].name,
                fields: []
            };
            for (let i in this.selected) {
                let key = this.selected[i];
                let item = this.fields[key];
                present.fields.push(item);
            }
            console.log("target", this.target);
            this.target.push(present);
        }
    }
}
</script>
<style type="text/css" lang="scss">
</style>